import { useEffect, useState } from 'react'
import { Button, message } from 'antd'

export default function Index () {
  const [installPath, setInstallPath] = useState('')

  useEffect(() => {
    window.ipcRenderer?.onMessage?.(message.info)
    window.ipcRenderer?.getInstallPath?.().then(setInstallPath)
  }, [])

  const [dir, setDir] = useState('')

  function openDialog () {
    window.ipcRenderer?.getFilePath?.().then(res => {
      setDir(res)
    })
  }

  function download () {
    window.ipcRenderer.download('https://s1.hct.plus/electron/hct_0.2.1.exe').then(res => {
      console.log(res)
    })
  }

  return <>
    <div>安装路径: {installPath}</div>
    <Button onClick={openDialog}>获取文件路径</Button>
    <div>{dir}</div>
    <Button onClick={download}>download</Button>
  </>
}
